package com.changhai.diabetes.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.changhai.diabetes.model.Concurrent;
import com.changhai.diabetes.model.ConcurrentResult;
import com.changhai.diabetes.service.ConcurrentService;
import com.changhai.diabetes.util.Constants;

/**
 * 并发及伴随症
 * 
 * @author Andy
 * 
 */
public class ConcurrentServiceImpl extends CommonServiceImpl implements ConcurrentService {

	public List<Concurrent> searchAllCons() {
		List<Concurrent> list = new ArrayList<Concurrent>();
		list = this.getList(Constants.DS_CHANGHAI, "concurrent.getAllConcurrents", null);
		return list;
	}

	public ConcurrentResult searchReByPatientId(Long patientid) {
		Object o = this.getObject(Constants.DS_CHANGHAI, "concurrentResult.getByPatientId", patientid);
		if (o != null && o instanceof ConcurrentResult) {
			return (ConcurrentResult) o;
		} else {
			ConcurrentResult re = new ConcurrentResult();
			re.setPatientid(patientid);
			return re;
		}
	}

	public void saveEditConcurrent(ConcurrentResult re) {
		if (re != null) {
			if (re.getSeqid() != null) {
				this.updateObject(Constants.DS_CHANGHAI, "concurrentResult.updateByPrimaryKey", re);
			} else {
				Long id = this.saveNewConcurrent(re);
				if (id != null && id > 0) {
					re.setSeqid(id);
					this.updateObject(Constants.DS_CHANGHAI, "concurrentResult.updateByPrimaryKey", re);
				}
			}
		}
	}

	public Long saveNewConcurrent(ConcurrentResult re) {
		Integer id = 0;
		if (re != null && re.getPatientid() != null) {
			id = this.insertObjectID(Constants.DS_CHANGHAI, "concurrentResult.insert", re);
		}
		return new Long(id);
	}
}
